using System;
using Common;

namespace device
{
	public class CommandCreator
	{
		public static RunCommand Command_Null()
		{
			RunCommand runCommand = new RunCommand();
			runCommand.RunCommandNo = -1;
			runCommand.RunCommandByte = new byte[6];
			return runCommand;
		}

		public static RunCommand Command_DeviceInfo()
		{
			RunCommand runCommand = new RunCommand();
			byte[] runCommandByte = new byte[6] { 161, 161, 238, 238, 238, 238 };
			runCommand.RunCommandNo = 0;
			runCommand.RunCommandByte = runCommandByte;
			return runCommand;
		}

		public static RunCommand Command_DarkCurrent()
		{
			RunCommand runCommand = new RunCommand();
			byte[] runCommandByte = new byte[6] { 171, 171, 238, 238, 238, 238 };
			runCommand.RunCommandNo = 1;
			runCommand.RunCommandByte = runCommandByte;
			return runCommand;
		}

		public static RunCommand Command_Calibration(byte n)
		{
			RunCommand runCommand = new RunCommand();
			byte[] array = new byte[6] { 0, 0, 238, 238, 238, 238 };
			array[0] = (byte)(164 + n);
			array[1] = (byte)(164 + n);
			byte[] runCommandByte = array;
			runCommand.RunCommandNo = 2;
			runCommand.RunCommandByte = runCommandByte;
			return runCommand;
		}

		public static RunCommand Command_Reset()
		{
			RunCommand runCommand = new RunCommand();
			byte[] runCommandByte = new byte[28]
			{
				187, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				5, 5, 187, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 5, 5, 238, 238, 238, 238
			};
			runCommand.RunCommandNo = 3;
			runCommand.CMD_HoldingTime_Minute = 0;
			runCommand.CMD_HoldingTime_Second = 5;
			runCommand.RunCommandByte = runCommandByte;
			return runCommand;
		}

		public static RunCommand Command_CloseHotlid(byte _UsedHotlid, int _HotlidSetTemperature, bool _HotlidIsHeating)
		{
			RunCommand runCommand = new RunCommand();
			byte b = 0;
			byte b2 = 0;
			byte b3 = 0;
			byte b4 = 0;
			if (!_HotlidIsHeating)
			{
				_HotlidSetTemperature = 0;
			}
			if (_UsedHotlid == 1)
			{
				b = 1;
				b2 = (byte)_HotlidSetTemperature;
			}
			if (_UsedHotlid == 2)
			{
				b3 = 1;
				b4 = (byte)_HotlidSetTemperature;
			}
			if (_UsedHotlid == 3)
			{
				b = 1;
				b2 = (byte)_HotlidSetTemperature;
				b3 = 1;
				b4 = (byte)_HotlidSetTemperature;
			}
			byte[] array = new byte[28]
			{
				187, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				1, 0, 187, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 1, 0, 238, 238, 238, 238
			};
			array[1] = b;
			array[2] = b2;
			array[3] = b3;
			array[4] = b4;
			array[11] = (byte)(0x7F & (byte)(b + b2 + b3 + b4 + 1));
			array[13] = b;
			array[14] = b2;
			array[15] = b3;
			array[16] = b4;
			array[23] = (byte)(0x7F & (byte)(b + b2 + b3 + b4 + 1));
			byte[] runCommandByte = array;
			runCommand.RunCommandNo = 4;
			runCommand.CMD_Segment = Utility.GetMessage("close_hotlid");
			runCommand.CMD_HoldingTime_Minute = 0;
			runCommand.CMD_HoldingTime_Second = 0;
			runCommand.RunCommandByte = runCommandByte;
			return runCommand;
		}

		public static RunCommand Command_Start(byte _UsedBlock, byte _ScanChannel, bool _compensator, bool _IsFast)
		{
			RunCommand runCommand = new RunCommand();
			byte b = 0;
			byte b2 = 0;
			byte b3 = 0;
			if ((_UsedBlock & 1) != 0)
			{
				b = (byte)(_ScanChannel + 64);
				b3 += 16;
			}
			if ((_UsedBlock & 2) != 0)
			{
				b2 = (byte)(_ScanChannel + 64);
				b3 += 8;
			}
			if (!_compensator)
			{
				b3 += 32;
			}
			if (_IsFast)
			{
				b3 += 64;
			}
			byte[] runCommandByte = new byte[28]
			{
				187,
				b,
				b,
				b,
				b,
				b2,
				b2,
				b2,
				b2,
				b3,
				0,
				(byte)(0x7F & (byte)(b * 4 + b2 * 4 + b3)),
				187,
				b,
				b,
				b,
				b,
				b2,
				b2,
				b2,
				b2,
				b3,
				0,
				(byte)(0x7F & (byte)(b * 4 + b2 * 4 + b3)),
				238,
				238,
				238,
				238
			};
			runCommand.RunCommandNo = 5;
			runCommand.CMD_Segment = Utility.GetMessage("hotlid_temperature_up");
			runCommand.CMD_HoldingTime_Minute = 0;
			runCommand.CMD_HoldingTime_Second = 5;
			runCommand.RunCommandByte = runCommandByte;
			return runCommand;
		}

		public static RunCommand Command_OpenHotlidA()
		{
			RunCommand runCommand = new RunCommand();
			byte[] runCommandByte = new byte[28]
			{
				187, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				3, 3, 187, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 3, 3, 238, 238, 238, 238
			};
			runCommand.RunCommandNo = 6;
			runCommand.CMD_Segment = Utility.GetMessage("open_hotlid");
			runCommand.CMD_HoldingTime_Minute = 0;
			runCommand.CMD_HoldingTime_Second = 0;
			runCommand.RunCommandByte = runCommandByte;
			return runCommand;
		}

		public static RunCommand Command_OpenHotlidB()
		{
			RunCommand runCommand = new RunCommand();
			byte[] runCommandByte = new byte[28]
			{
				187, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				4, 4, 187, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 4, 4, 238, 238, 238, 238
			};
			runCommand.RunCommandNo = 7;
			runCommand.CMD_Segment = Utility.GetMessage("open_hotlid");
			runCommand.CMD_HoldingTime_Minute = 0;
			runCommand.CMD_HoldingTime_Second = 0;
			runCommand.RunCommandByte = runCommandByte;
			return runCommand;
		}

		public static RunCommand Command_Temperature(byte _UsedBlock, string _SegmentName, string _StepName, int _Cycles, double _SetTemperatureValue, int _HoldingTimeMinute, int _HoldingTimeSecond, bool _FluorescenceTest, double _V, bool Continue_Mark, bool isMeltingSegment, double _DeltaTemperature = 0.0)
		{
			RunCommand runCommand = new RunCommand();
			byte b = 0;
			byte b2 = 0;
			byte b3 = 0;
			if ((_UsedBlock & 1) != 0)
			{
				b = 15;
			}
			if ((_UsedBlock & 2) != 0)
			{
				b2 = 15;
			}
			b3 = ((!Continue_Mark) ? ((byte)Math.Round(_V * 10.0)) : ((byte)Math.Round(_V * 100.0 + 64.0)));
			int num = (int)Math.Round((_SetTemperatureValue + _DeltaTemperature) * 10.0);
			if (num > 1020)
			{
				num = 1020;
			}
			if (num < 40)
			{
				num = 40;
			}
			byte b4 = (byte)num;
			byte b5 = (byte)(num >> 8);
			if ((b4 & 0x80) != 0)
			{
				b4 &= 0x7F;
				b5 |= 4;
			}
			byte[] array = new byte[28]
			{
				187, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 187, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 0, 0, 238, 238, 238, 238
			};
			array[1] = b;
			array[2] = b2;
			array[3] = b3;
			array[9] = b5;
			array[10] = b4;
			array[11] = (byte)(0x7F & (byte)(b + b2 + b3 + b5 + b4));
			array[13] = b;
			array[14] = b2;
			array[15] = b3;
			array[21] = b5;
			array[22] = b4;
			array[23] = (byte)(0x7F & (byte)(b + b2 + b3 + b5 + b4));
			byte[] runCommandByte = array;
			runCommand.RunCommandNo = 8;
			runCommand.CMD_Segment = _SegmentName;
			runCommand.CMD_Step = _StepName;
			runCommand.CMD_Cycles = _Cycles;
			runCommand.CMD_SetTemperature = _SetTemperatureValue;
			runCommand.CMD_HoldingTime_Minute = _HoldingTimeMinute;
			runCommand.CMD_HoldingTime_Second = _HoldingTimeSecond;
			runCommand.CMD_V = _V;
			runCommand.RunCommandByte = runCommandByte;
			runCommand.FluorescenceTest = _FluorescenceTest;
			runCommand.isContinue = Continue_Mark;
			runCommand.isMeltingSegment = isMeltingSegment;
			return runCommand;
		}

		public static RunCommand Command_FluorescenceTest(byte _UsedBlock)
		{
			RunCommand runCommand = new RunCommand();
			byte b = 0;
			byte b2 = 0;
			if ((_UsedBlock & 1) != 0)
			{
				b = 15;
			}
			if ((_UsedBlock & 2) != 0)
			{
				b2 = 15;
			}
			byte[] array = new byte[28]
			{
				187, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				2, 0, 187, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 2, 0, 238, 238, 238, 238
			};
			array[1] = b;
			array[2] = b2;
			array[11] = (byte)(0x7F & (byte)(b + b2 + 2));
			array[13] = b;
			array[14] = b2;
			array[23] = (byte)(0x7F & (byte)(b + b2 + 2));
			byte[] runCommandByte = array;
			runCommand.RunCommandNo = 9;
			runCommand.RunCommandByte = runCommandByte;
			return runCommand;
		}

		public static RunCommand Command_Stop(byte _UsedBlock)
		{
			RunCommand runCommand = new RunCommand();
			byte b = 0;
			byte b2 = 0;
			byte b3 = 0;
			if ((_UsedBlock & 1) != 0)
			{
				b = 15;
				b3 += 16;
			}
			if ((_UsedBlock & 2) != 0)
			{
				b2 = 15;
				b3 += 8;
			}
			byte[] array = new byte[28]
			{
				187, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				7, 0, 187, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 7, 0, 238, 238, 238, 238
			};
			array[1] = b;
			array[2] = b2;
			array[9] = b3;
			array[11] = (byte)(0x7F & (byte)(b + b2 + b3 + 7));
			array[13] = b;
			array[14] = b2;
			array[21] = b3;
			array[23] = (byte)(0x7F & (byte)(b + b2 + b3 + 7));
			byte[] runCommandByte = array;
			runCommand.RunCommandNo = 10;
			runCommand.RunCommandByte = runCommandByte;
			return runCommand;
		}
	}
}
